package com.bainaeco.framework.base.exception;

import com.bainaeco.framework.util.SystemCodeStatus;
import com.netflix.hystrix.exception.HystrixBadRequestException;

public abstract class BaseException extends HystrixBadRequestException{

	private static final long serialVersionUID = 1L;
	
	private Object[] args;
	
	private Object Data;
	
	private int httpStatus = SystemCodeStatus.SUCCESS;
	
	public abstract int getErrorCode();

	protected BaseException(Object... args){
		super("");
		this.args = args;
	}
	
	protected BaseException(String message, Throwable cause, Object... args){
		super(message, cause);
	    this.args = args;
	}
	
	protected BaseException(String message, Object... args){
	    super(message);
	    this.args = args;
	}
	
	protected BaseException(Throwable cause, Object... args){
		super("", cause);
	    this.args = args;
	}
	
	public Object[] getArgs(){
	    return this.args;
	}
	
	public void setArgs(Object[] args){
		this.args = args;
	}

	public Object getData() {
		return Data;
	}

	public void setData(Object data) {
		Data = data;
	}
	
	public int getHttpStatus() {
		return httpStatus;
	}
	
	/**
	 * 当前项目在spring cloud中用了 hystrix 的回退机制
	 * 实例本类后, 调用该方法, 把普通自定义异常转为微服务调用方可以识别的自定义异常
	 * 否则, 微服务调用方会自己判断调用失败, 因为对方抛出了异常
	 */
	public void changeToHystrixException() {
		this.httpStatus = SystemCodeStatus.FAILED;
	};
}
